Skip to content

fix(research-edition): patch both aw-qt port fallbacks - #1584

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/research-edition-duplicated-port-fallback
Open

TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/research-edition-duplicated-port-fallback

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

What

scripts/patch_research_edition_profile.py refuses to build when a patch target is ambiguous. aw-qt#144 added a second copy of the port fallback:

default_port = 5666 if is_testing(profile) else 5600

in dashboard_auth(), next to the existing one in _read_server_port(). The patcher's 4-space-indented target string then matched both (it is a substring of the 12-space copy), so the nightly [latest submodules] run failed every Qt leg with:

PatchError: aw-qt/aw_qt/config.py: expected exactly one match for
[aw-qt _read_server_port fallback], found 2

Nightly run: https://github.com/ActivityWatch/activitywatch/actions/runs/45932774740

Fix

  • Match the expression without its indentation and declare counts=(1, 2) on the patch: the pinned aw-qt (c31456c) has only _read_server_port, the upstream tip has both call sites. Every allowed occurrence is rewritten; any other count still aborts, so a future third copy cannot slip through unpatched.
  • Patching dashboard_auth matters for the research build: it compares a config file's port against the live one, and the generated research config is written with every value commented out, so its own fallback must be 5667 or the tray opens an unauthenticated dashboard against the research server.

Verification

  • patch_research_edition_profile.py qt --check passes against aw-qt at the pinned SHA and at the upstream tip (c825b78).
  • patch_research_edition_profile.py tauri --check passes.
  • pytest scripts/tests/test_patch_research_edition_profile.py — 38 passed, including two new tests for the multi-site count (rewrites both copies; a third copy fails closed).

No submodule pins changed.

Note: the pr-overlap guard flagged #1576 because it also touches these two files. The changes are independent (that one is the Windows uninstall Run value, this one is the aw-qt port fallback), and they sit in different regions, so I opened this separately rather than stacking an unrelated fix onto a packaging PR.

aw-qt#144 added a second `default_port = 5666 if is_testing(profile) else
5600` fallback in `dashboard_auth`, alongside the existing one in
`_read_server_port`. The patcher's exact-substring match then found two
copies and refused to build, so the nightly `[latest submodules]` release
went red for every Qt leg while the pinned tree still had one copy.

Match the expression without indentation and allow one or two occurrences,
rewriting every one of them: the pinned aw-qt has only `_read_server_port`,
the upstream tip has both. `dashboard_auth` compares a config file's port
against the live one and the generated research config leaves `port`
commented out, so it must fall back to 5667 too or the tray opens an
unauthenticated dashboard against the research server.

A count outside the declared set still aborts, so a future third copy
cannot slip through unpatched.

Git-Session-Id: a478cc17-38ae-55f2-aed4-9ebb5029dcde
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

What changed: 2 files, +74/-7 in scripts/tests/, scripts/
Riskiest file: scripts/patch_research_edition_profile.py (+29/-7)
Test: make typecheck

Review guide

Key files

  • scripts/tests/test_patch_research_edition_profile.py (+45/-0, Δ45)
  • scripts/patch_research_edition_profile.py (+29/-7, Δ36)

Suggested verification

  • make typecheck

Auto-posted by scripts/github/pr-warmup-review-guide.py for #1584.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with two non-blocking findings from the previous review still open.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with two non-blocking findings from the previous review still open.

Findings

  1. P2 Tuple is not imported ▶
  2. P2 Tests miss the real patch ▶

Summary

The patcher now accepts one or two copies of the Qt port fallback and rewrites every accepted copy to use port 5667.

  • The Qt research build patches every supported aw-qt port fallback to 5667.

Reviews (2) · Last reviewed commit: "fix(research-edition): patch both aw-qt ..." · Reviewed by Greptile

Git-Session-Id: 032ccdc3-dbca-5df5-ae18-103dd80fd43d
@TimeToBuildBob

TimeToBuildBob commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Adds a counts: tuple[int, ...] = (1,) field to the Patch dataclass. apply_patches now accepts any occurrence count listed in patch.counts and rewrites every occurrence with text.replace(patch.old, patch.new). The aw-qt config.py port patch now matches the indentation-free expression default_port = 5666 if is_testing(profile) else 5600 with counts=(1, 2), so both the _read_server_port copy and the dashboard_auth copy are rewritten. New tests cover type-hint resolution, rewriting with one and two copies, and failure when there are three copies.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads.

1 advisory finding (summary-only, not scored)

These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.

⚠️ P2 medium · 🔒 security — scripts/patch_research_edition_profile.py:267

With counts=(1, 2), the patcher cannot tell the pinned aw-qt (one real site) apart from an upstream tree that has two call sites where one has drifted. Take a future aw-qt where _read_server_port is refactored to, say, default_port = DEFAULT_PORT_FALLBACK but dashboard_auth still contains default_port = 5666 if is_testing(profile) else 5600. text.count(patch.old) returns 1, 1 in patch.counts passes, and only the matched copy is rewritten. The refactored site keeps resolving to 5600 and the build succeeds. The same silent pass happens in the reverse direction. The PR description itself says an unpatched copy makes the tray open an unauthenticated dashboard against the server on 5667. This is exactly the silent miss the module docstring promises to prevent. Split this into two per-site patches anchored on distinct surrounding context, gated by aw-qt version. Alternatively, accept only 2 and bump the pin. Either keeps each site fail-closed on its own.

How this was verified: In apply_patches (lines 701-716), the only guard is occurrences not in patch.counts followed by an unconditional text.replace. Nothing records which call site matched. The old string at line 264 has no indentation or neighbouring context, so it cannot tell the two sites apart.

Files changed (2) — the diff as I read it
  • scripts/patch_research_edition_profile.py — Adds Patch.counts, switches the occurrence check to occurrences not in patch.counts with a count-aware error message, replaces all occurrences, and relaxes the aw-qt config port patch to an unindented target with counts=(1, 2).
  • scripts/tests/test_patch_research_edition_profile.py — Imports get_type_hints and adds test_patch_type_hints_resolve, parametrized test_declared_multi_site_patch_rewrites_every_copy (1 or 2 copies), and test_declared_multi_site_patch_fails_closed_on_a_third_copy.

Reviewed 158d3a4aafeb · panel: claude-code:claude-opus-5-5 · subscription engine · 28s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

@TimeToBuildBob

TimeToBuildBob commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Review findings addressed — maintainer handoff

  • Fixed: both valid, non-blocking P2 findings in 158d3a4. Replaced the unresolved Tuple annotation with tuple[int, ...]; the new get_type_hints(Patch) regression failed before the fix and passes now. The one/two-copy and three-copy tests use the production PORT_PATCHES_QT entry instead of constructing their own. An in-memory mutation removing (1, 2) from that entry correctly fails the two-copy regression. Replied on and resolved both bot threads.
  • Remaining: neither original inline finding remains. The automatic current-head AI pass added one summary-only P2 advisory: accepting one or two matches cannot detect a hypothetical future refactor that removes one of two target expressions. This is a valid future-drift limitation, not a defect observed in either supported tree: pinned aw-qt has one matching site, and c825b78 has two, both verified below. Treating every future semantic rewrite as detectable by an exact-substring patcher exceeds this repair's scope; no version gate or pin bump added. No blocking bug or security finding was reported in either pass.
  • Verified against: classifications checked on reviewed head 1081c3aff38679491daed4e3ba39b1935624dc9a; fixes checked locally on new head 158d3a4aafeb3c929947353a9b3f8bcdadbe3d90. All 40 tests pass with the pinned submodules checked out; both qt --check and tauri --check pass. Separately patched the real aw-qt c825b78d52d64a5636bb1add13c6eb6e6cd1fc1a config in a temporary tree: both fallbacks become 5667 and the result compiles. No submodule pins changed. The existing Greptile 5/5 covers the previous head, not this follow-up commit. The automatic AI sweep has since reviewed 158d3a4aafeb at 5/5 with no P0/P1 or inline findings and the one future-drift advisory above.
  • CI: new-head build, CodeQL and research packaging checks are pending; greeting passed. Not claiming CI-green or merge-ready yet.
  • Domain risk: this touches research-edition build-time rewriting, not ordinary runtime defaults. A maintainer's packaged research-build smoke test should confirm the tray opens an authenticated dashboard on 5667 while a standard install remains on 5600.
  • Convergence: detector reports verdict=converged, zero unresolved P1/P2, and round_convergence.stable_rounds=0 (status=no_current_blocking, required stable rounds 2). That is not evidence of two stable rounds. No additional Greptile review requested.

Recommendation: no reported finding remains to fix; await current-head CI/review evidence, then maintainer judgment. No merge performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant